#include "server.hpp"

using namespace std;

void t1()
{
    Buffer b1;
    int arr[] = {666,888,1616,8686};
    cout << "b1.ReadableSize() = " << b1.ReadableSize() << endl;
    cout << "-----------------------------------------" << endl;
    b1.Write(arr,sizeof(arr));
    cout << "b1.ReadableSize() = " << b1.ReadableSize() << endl;
    // cout << "-----------------------------------------" << endl;
    int res[10] = {0};
    // for(auto &i : res)
    // {
    //     cout << i << " ";
    // }
    // cout << endl;
    cout << "-----------------------------------------" << endl;
    b1.Read(res, b1.ReadableSize());
    for(auto &i : res)
    {
        cout << i << " ";
    }
    cout << endl;
    cout << "b1.ReadableSize() = " << b1.ReadableSize() << endl;

}

void t2()
{
    Buffer b1;
    string s = "Hello buffer, im writing!!!";
    cout << "b1.ReadableSize() = " << b1.ReadableSize() << endl;
    cout << "-----------------------------------------" << endl;
    b1.WriteSting(s);
    cout << "b1.ReadableSize() = " << b1.ReadableSize() << endl;
    cout << "-----------------------------------------" << endl;
    string res;
    res.resize(100);
    res = b1.ReadAsString(b1.ReadableSize());
    cout << res << endl;
    cout << "b1.ReadableSize() = " << b1.ReadableSize() << endl;
}

void t3()
{
    Buffer b1;
    cout << "b1.ReadableSize() = " << b1.ReadableSize() << endl;
    cout << "-----------------------------------------" << endl;

    for(int i = 0; i < 300; i++)
    {
        string str = "hello!!!!!!" + to_string(i) + '\r' + '\n';
        b1.WriteSting(str);
    }

    cout << "b1.ReadableSize() = " << b1.ReadableSize() << endl;
    cout << "-----------------------------------------" << endl;

    int i = 0;
    while(b1.ReadableSize() > 0)
    {
        string line = b1.GetLine();
        cout << "line-" << i << " : " << line;
        cout << "b1.ReadableSize() = " << b1.ReadableSize() << endl;
        i++;
    }

    // string res = b1.ReadAsString(b1.ReadableSize());
    // cout << res;
    // cout << "b1.ReadableSize() = " << b1.ReadableSize() << endl;
    // cout << "-----------------------------------------" << endl;
}

int main()
{
    t1();
    cout << "=========================================================================" << endl;
    t2();
    cout << "=========================================================================" << endl;
    t3();



    return 0;
}